package com.ruoyi.system.Fdongbei.service.dibang;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.system.Fdongbei.domain.dibang.HuayanDo;
import com.ruoyi.system.Fdongbei.domain.dibang.ShdzDo;
import com.ruoyi.system.Fdongbei.domain.dibang.WlccfwDo;
import com.ruoyi.system.Fdongbei.domain.dibang.ZczmDo;
import com.ruoyi.system.Fdongbei.domain.vo.reqvo.KdpReqVo;
import com.ruoyi.system.Fdongbei.domain.vo.reqvo.PageReqInfo;
import com.ruoyi.system.Fdongbei.domain.vo.reqvo.ZaiChangCheReqVo;
import com.ruoyi.system.Fdongbei.domain.vo.resvo.*;
import com.ruoyi.system.Fdongbei.mapper.dibang.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

@Service
@DataSource(value = DataSourceType.LY002_L)
public class WorkService {

    @Resource
    ShdzDoMapper shdzDoMapper;

    @Resource
    ZczmDoMapper zczmDoMapper;

    @Resource
    WlccfwDoMapper wlccfwDoMapper;

    @Resource
    HuayanDoMapper huayanDoMapper;

    @Resource
    GuozhongDoMapper guozhongDoMapper;

    public AjaxResult getCustomerInfo(PageReqInfo pageReqInfo) {
        CustomerResVo customerResVo = new CustomerResVo();
        List<ShdzDo> shdzDos = shdzDoMapper.selectInfo(pageReqInfo);
        Integer sum = shdzDoMapper.getSum(pageReqInfo);
        customerResVo.setShdzList(shdzDos);
        customerResVo.setTotal(sum);
        return AjaxResult.success(customerResVo);
    }

    public AjaxResult delCustomer(Integer id) {
        shdzDoMapper.deleteByPrimaryKey(id);
        return AjaxResult.success();
    }

    public AjaxResult addCustomer(ShdzDo shdzDo) {
        shdzDoMapper.insert(shdzDo);
        return AjaxResult.success();
    }

    public AjaxResult updateCustomer(ShdzDo shdzDo) {
        shdzDoMapper.updateByPrimaryKeySelective(shdzDo);
        return AjaxResult.success();
    }

    public AjaxResult getZczmInfo(PageReqInfo pageReqInfo) {
        ZczmResVo zczmResVo = new ZczmResVo();
        List<ZczmDo> zczmDos = zczmDoMapper.selectInfo(pageReqInfo);
        Integer sum = zczmDoMapper.getSum(pageReqInfo);
        zczmResVo.setZczmList(zczmDos);
        zczmResVo.setTotal(sum);
        return AjaxResult.success(zczmResVo);
    }

    public AjaxResult delZczm(Integer id) {
        zczmDoMapper.deleteByPrimaryKey(id);
        return AjaxResult.success();
    }

    public AjaxResult addZczm(ZczmDo zczmDo) {
        zczmDoMapper.insert(zczmDo);
        return AjaxResult.success();
    }

    public AjaxResult updateZczm(ZczmDo zczmDo) {
        zczmDoMapper.updateByPrimaryKeySelective(zczmDo);
        return AjaxResult.success();
    }

    public AjaxResult getKdpInfo(KdpReqVo kdpReqVo) {
        KdpResVo kdpResVo = new KdpResVo();
        List<WlccfwDo> kdpDos = wlccfwDoMapper.selectInfo(kdpReqVo);
        Integer sum = wlccfwDoMapper.getSum(kdpReqVo);
        kdpResVo.setKdpList(kdpDos);
        kdpResVo.setTotal(sum);
        return AjaxResult.success(kdpResVo);
    }

    public AjaxResult delKdp(Integer id) {
        wlccfwDoMapper.deleteByPrimaryKey(id);
        return AjaxResult.success();
    }

    public AjaxResult addKdp(WlccfwDo wlccfwDo) {
        wlccfwDoMapper.insert(wlccfwDo);
        return AjaxResult.success();
    }

    public AjaxResult updateKdp(WlccfwDo wlccfwDo) {
        wlccfwDoMapper.updateByPrimaryKeySelective(wlccfwDo);
        return AjaxResult.success();
    }

<<<<<<< HEAD
    public AjaxResult selectZaiChang(ZaiChangCheReqVo zaiChangCheReqVo) {
=======
    public AjaxResult selectZaiChang(ZaiChangCheReqVo zaiChangCheReqVo){
>>>>>>> b4a0e2dba4b1f1e0b05e6d155df4272830d06f27
        ZaiChangListResVo zaiChangListResVo = new ZaiChangListResVo();
        List<ZaiChangCheResVo> zaiChangInfo = guozhongDoMapper.getZaiChangInfo(zaiChangCheReqVo);
        Integer zaiChangTotal = guozhongDoMapper.getZaiChangTotal(zaiChangCheReqVo);
        List<String> czbhs = zaiChangInfo.stream().map(ZaiChangCheResVo::getCzbh).collect(Collectors.toList());

        Map<String, HuayanDo> huayanDoMap = null;
        if (Objects.nonNull(czbhs) && !czbhs.isEmpty()) {
            huayanDoMap = huayanDoMapper.selectByCzbhs(czbhs);
        }
<<<<<<< HEAD
        if (Objects.nonNull(huayanDoMap)) {
            for (ZaiChangCheResVo zaiChangCheResVo : zaiChangInfo) {
                HuayanDo huayanDo = huayanDoMap.get(zaiChangCheResVo.getCzbh());
                if (Objects.nonNull(huayanDo)) {
=======
        if(Objects.nonNull(huayanDoMap)){
            for(ZaiChangCheResVo zaiChangCheResVo : zaiChangInfo){
                HuayanDo huayanDo = huayanDoMap.get(zaiChangCheResVo.getCzbh());
                if(Objects.nonNull(huayanDo)){
>>>>>>> b4a0e2dba4b1f1e0b05e6d155df4272830d06f27
                    zaiChangCheResVo.setRzdj(huayanDo.getRzdj());
                    zaiChangCheResVo.setRzsl(huayanDo.getRzsl());
                }
            }
        }
        zaiChangListResVo.setList(zaiChangInfo);
        zaiChangListResVo.setTotal(zaiChangTotal);
        return AjaxResult.success(zaiChangListResVo);
    }
}
